<!--
 * @Author: 施伟略
 * @Date: 2020-06-29 15:19:10
 * @LastEditTime: 2020-07-02 23:38:30
 * @LastEditors: Please set LastEditors
 * @Description: 各问题分类
 * @FilePath: \jkShop\shop\src\pages\help\components\cliPro.vue
--> 
<template>
  <div class="classifyProblem">
    <!-- 顶部导航 -->
    <van-nav-bar :title="name" left-text="返回" left-arrow @click-left="onClickLeft" />
    <!-- 搜索 -->
    <van-search background="#f4f4f4" v-model="value" placeholder="输入问题关键词" @search="onSearch" />
    <van-divider />
    <!-- 搜索结果统计 -->
    <div class="total">{{'全部问题'+'>'+name}}</div>

    <ul class="ul-content" v-if="specifys.specify">
      <li class="li-content" v-for="(item,idx) of specifys.specify" :key="idx">
        <router-link :to="{path:'/questionDetails',query:{id:item.id}}">
          <span>></span>
          {{item.title}}
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import * as api from "@/api/apiList/help/help.js";
import { Toast } from "vant"
export default {
  props: ["id", "name"],
  data() {
    return {
      value:'', //搜索关键字
      datas: [], //帮助分类页数据
      specifys: [] //各分类问题数据
    };
  },
  methods: {
    // 返回上一页
    onClickLeft() {
      this.$router.go(-1);
    },
    // 回车键触发搜索
    onSearch() {
      if (this.value === "" || this.value == null) {
        Toast("请输入关键字再搜索！");
      } else {
        this.$router.push({
          path: "/searchResults",
          query: { val: this.value }
        });
      }
    },
    // 获取帮助分类页接口数据
    async API_category() {
      return await api.help_category();
    },
    //根据路由传递过来的分类id筛选显示问题
    filterDatas() {
      let categoryId = parseInt(this.id);
      switch (categoryId) {
        case 5:
          this.specifys = this.datas[0];
          break;
        case 6:
          this.specifys = this.datas[1];
          break;
        case 7:
          this.specifys = this.datas[2];
          break;
        case 10:
          this.specifys = this.datas[3];
          break;
        default:
          break;
      }
      return this.specifys;
    }
  },
  watch: {
    // 监听路由传递的id
    id: {
      handler() {
        // console.log(val);
        this.filterDatas();
      }
    }
  },
  async created() {
    let res = await this.API_category();
    this.datas = res.data;
    // console.log(this.datas);
    this.filterDatas();
  }
};
</script>

<style lang="scss" scoped>
@import "@/style/help/help.scss"
</style>